import os
import json

# path = '/'
# filename = '10_10001'
# result = []

# 将查询结果直接输出
def call(arg, *args, **kwargs):
    path = arg["path"]
    filename = arg["filename"]
    result = {}
    result1 = []
    i = 0
    for root, lists, files in os.walk(path):
        for file in files:
            if filename in file:
                i = i + 1
                # print(root)
                write = os.path.join(root, file)
                # print('%d %s' % (i, write))

                result1.append(write)
                result["result"] = result1
                # result = json.dumps({str(k): result[k] for k in result})

    return result

    # result.append(write)


# 将查询结果保存在文本文档中
# def find_file_and_putin_txt():
#     i = 0
#     open('E:\Python\\find_file.txt', mode='w').close()
#     for root, lists, files in os.walk(path):
#         for file in files:
#             if filename in file:
#                 i = i + 1
#                 write = os.path.join(root, file)
#
#                 file_txt = open('C:\User\\find_file.txt', mode='a+')
#                 file_txt.write('%d %s \n' % (i, write))
#                 result.append(write)


if __name__ == '__main__':
    arg = {
        "path": "/",
        "filename": "10_10001"
    }
    print(call(arg))
    # find_file_and_putin_txt()
